//
//  DYMemberManagerCell.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/19.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYMemberManagerCell.h"

@interface DYMemberManagerCell ()

@property (nonatomic,strong)DYMemberManagerView *nameView;
@property (nonatomic,strong)DYMemberManagerView *moneyView;
@property (nonatomic,strong)DYMemberManagerView *phoneView;
@property (nonatomic,strong)DYMemberManagerView *numberView;

@property (nonatomic,strong)UILabel *line;
@property (nonatomic,strong)UILabel *timeLabel;
@property (nonatomic,strong)UIButton *billButton;

@end



@implementation DYMemberManagerCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(void)dy_initUI
{
    [super dy_initUI];
    
    self.hideSeparatorLabel=YES;
    
    [self xhq_noneSelectionStyle];
    
    self.nameView=({
        DYMemberManagerView *view=[[DYMemberManagerView alloc]init];
        view.titleLabel.text=@"用户昵称：";
        view;
    });
    
    self.moneyView=({
        DYMemberManagerView *view=[[DYMemberManagerView alloc]init];
        view.titleLabel.text=@"卡内余额：";
        view.circleView.backgroundColor=[UIColor xhq_red];
        view;
    });
    
    self.phoneView=({
        DYMemberManagerView *view=[[DYMemberManagerView alloc]init];
        view.titleLabel.text=@"手机：";
        view;
    });
    
    self.numberView=({
        DYMemberManagerView *view=[[DYMemberManagerView alloc]init];
        view.titleLabel.text=@"卡片数量：";
        view.circleView.backgroundColor=[UIColor xhq_red];
        view;
    });
    
    
    self.line=({
        UILabel *line=[UILabel xhq_lineLabel];
        line;
    });
    
    self.timeLabel =({
        UILabel *label=[Utils labelWithTitleFontSize:12 textColor:[UIColor xhq_content] alignment:0];
        label;
    });
    
    self.billButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(billButtonClick) target:self title:@"历史账单" image:@"arrow_right" font:12 textColor:[UIColor xhq_content]];
        button;
    });
    
    [self addSubview:self.nameView];
    [self addSubview:self.moneyView];
    [self addSubview:self.phoneView];
    [self addSubview:self.numberView];
    [self addSubview:self.line];
    [self addSubview:self.timeLabel];
    [self addSubview:self.billButton];
    
    
    [self.nameView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(8));
        make.top.equalTo(BILIHEIGHT(10));
        make.height.equalTo(BILIHEIGHT(20));
        make.width.equalTo(kScreenWidth/2-BILIWIDTH(8));
    }];
    
    [self.moneyView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameView.right);
        make.right.equalTo(BILIWIDTH(-8));
        make.height.equalTo(self.nameView);
        make.centerY.equalTo(self.nameView);
    }];
    
    
    [self.phoneView makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.height.equalTo(self.nameView);
        make.top.equalTo(self.nameView.bottom).offset(BILIHEIGHT(5));
    }];
    
    [self.numberView makeConstraints:^(MASConstraintMaker *make) {
        make.right.width.height.equalTo(self.moneyView);
        make.centerY.equalTo(self.phoneView);
    }];
    
    [self.line makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(8));
        make.right.equalTo(BILIWIDTH(-8));
        make.top.equalTo(self.numberView.bottom).offset(BILIHEIGHT(10));
        make.height.equalTo(BILIWIDTH(0.7));
    }];
    
    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameView);
        make.top.equalTo(self.line.bottom);
        make.height.equalTo(BILIHEIGHT(25));
    }];
    
    [self.billButton makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(BILIWIDTH(-10));
        make.height.equalTo(BILIHEIGHT(25));
        make.top.equalTo(self.line.bottom);
    }];
    
    [self.billButton placeImageTitlePosition:ZYButtonImagePositionRight space:BILIWIDTH(7)];
    
    self.timeLabel.text=@"开机时间：";
    
    NSString *textStr = @"32张";// 下划线
    self.numberView.titleLabel.text=[NSString stringWithFormat:@"%@%@",@"卡片数量：",textStr];
    NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:self.numberView.titleLabel.text]; //赋值
    [attribtStr addAttributes:attribtDic range:NSMakeRange(@"卡片数量：".length, textStr.length)];
    
    self.numberView.titleLabel.attributedText = attribtStr;

}
-(void)billButtonClick
{
    !self.billBlock?:self.billBlock();
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end


@implementation DYMemberManagerView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame]) {
        [self initView];
    }
    return self;
}
-(void)initView
{
    
    self.circleView = ({
        UIView *view=[[UIView alloc]init];
        view.backgroundColor=[UIColor xhq_base];
        [view xhq_cornerRadius:BILIWIDTH(2)];
        view;
    });
    self.titleLabel = ({
        UILabel *label=[Utils labelWithTitleFontSize:14 textColor:[UIColor xhq_aTitle] alignment:0];
        label;
    });
    
    
    [self addSubview:self.circleView];
    [self addSubview:self.titleLabel];
    
    [self.circleView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(0));
        make.centerY.equalTo(self);
        make.width.height.equalTo(BILIWIDTH(4));
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.circleView.right).offset(BILIWIDTH(3));
        make.top.bottom.equalTo(0);
        make.width.equalTo(kScreenWidth/2-BILIWIDTH(20));
    }];
 
    
}
@end
